package org.flower.web.servlet;

import com.alibaba.fastjson.JSON;
import org.flower.dao.ProvinceDao;
import org.flower.dao.impl.ProvinceDaoImpl;
import org.flower.entity.Province;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author 29091
 */
@WebServlet("/user/province.shtml")
public class provincesServlet extends HttpServlet {
    /**
     * 省市地区
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置字符集编码
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        //创建省市接口实现类
        ProvinceDao pdao = new ProvinceDaoImpl();
        //页面获取参数
        String pid = request.getParameter("pid");
        List<Province> provincesList = pdao.getAllProByPid(Integer.parseInt(pid));
        response.getWriter().print(JSON.toJSONString(provincesList));


    }
}
